<template>
	<view>
		<view class="content">
			<view class="a1" style="margin-top: 0;">
				<image src="https://flash-cloud.oss-cn-hangzhou.aliyuncs.com/dingwei1.png" class="a2"></image>
				<view class="a3">
					<view class="a9">
						<input type="text" placeholder="点击选择地址" disabled="true" placeholder-class="pc" @click="chooseAddress" v-model="address"/>
					</view>
					<image src="https://flash-cloud.oss-cn-hangzhou.aliyuncs.com/jiantou1.png" class="a7"></image>
				</view>
			</view>
			<view class="a8"></view>
			<view class="a1">
				<image src="https://flash-cloud.oss-cn-hangzhou.aliyuncs.com/lou1.png" class="a2"></image>
				<view class="a3">
					<view class="a9">
						<input type="text" placeholder="请补充具体楼层门牌号" placeholder-class="pc" v-model="addressReplenish"/>
					</view>
				</view>
			</view>
			<view class="a8"></view>
			<view class="a1">
				<image src="https://flash-cloud.oss-cn-hangzhou.aliyuncs.com/dianhua1.png" class="a2"></image>
				<view class="a3">
					<view class="a9">
						<input type="text" placeholder="请补充电话号码" placeholder-class="pc" v-model="phone"/>
					</view>
				</view>
			</view>
			<view class="a8"></view>
			<view class="a1">
				<image src="https://flash-cloud.oss-cn-hangzhou.aliyuncs.com/lianxiren.png" class="a2"></image>
				<view class="a3">
					<view class="a9">
						<input type="text" placeholder="请填写联系人姓名" placeholder-class="pc" v-model="name"/>
					</view>
				</view>
			</view>
			<view class="a8"></view>
		</view>
		<view class="b1">
			<view class="b2">智能填写</view>
			<view class="b3">
				<input type="text" placeholder="粘贴地址信息,自动拆分姓名、电话和地址" placeholder-class="pc" v-model="copyMessage"/>
			</view>
			<view class="b4">
				<view class="b5" @click="photoDistinguish">
					<image src="https://flash-cloud.oss-cn-hangzhou.aliyuncs.com/tupian2.png" class="b6"></image>
					<view class="b7">图片识别</view>
				</view>
				<view class="b8" @click="getAddress()">识别</view>
			</view>
		</view>
		<view class="confirm" @click="handleConfirm">
			确定
		</view>
	</view>
</template>

<script>
	import smartAddress from '../../../static/smartAddress.js';
	export default {
		data() {
			return {
				//复制的地址信息
				copyMessage:'',
				phone:'',
				name:'',
				addressDetail:'',
				address:'',
				addressTitle:'',
				//经纬度
				location:'',
				//门牌号补充
				addressReplenish:'',
				//发/收货地址标记
				method:0
			}
		},
		onShow() {
			var that=this;
			//获取上页选择的地址
			uni.$on("takeAddress",function(res){
				that.address=res;
			})
			uni.$on("takeLocation",function(res){
				that.location=res;
			})
		},
		onLoad(options) {
			var that=this;
			//识别发货或者收货
			that.method=options.method;
			that.address=options.address?options.address:''
			that.location=options.location?options.location:''
		},
		methods: {
				/* 地址识别 */
			getAddress(){
			var res = smartAddress.processAddress(this.copyMessage)
			this.phone=res.phone
			this.name=res.name
			this.addressDetail=res.address
			},
			//选择地址
			chooseAddress(){
				var that=this;
				//发货
				if(that.method==0){
					uni.navigateTo({
						url:'../chooseTakeAddress/chooseTakeAddress?pageType=0'
					})
				}else if(that.method==1){
					uni.navigateTo({
						url:'../chooseReceivingAddress/chooseReceivingAddress?pageType=0'
					})
				}
				
			},
			//保存
			handleConfirm(){
				var that=this;
				that.http.sendRequest("/flashCloud/address/add",'post',{
					addressDetails:that.address,
					addressReplenish:that.addressReplenish,
					phone:that.phone,
					userName:that.name,
					userId:uni.getStorageSync('userId'),
					lonLat:that.location
				}).then(function(res){
					if(res.code==200){
						//如果是发货地址返回首页
						if(that.method==0){
							uni.$emit("takeAddressReplenish",that.addressReplenish);
							uni.setStorageSync('takeAddressId',res.addressId)
							uni.switchTab({
								url:'../../index/index'
							})
						}else if(that.method==1){
							//如果是收货地址跳转订单页
							uni.setStorageSync('recevingAddressId',res.addressId)
							uni.navigateTo({
								url:'../../take_order/takeOrderForm/takeOrderForm'
							})
						}else if(that.method==3){
							//如果是订单页跳转过来的(取)
							uni.setStorageSync('takeAddressId',res.addressId);
							uni.navigateBack({
								delta:2
							})
						}else if(that.method==4){//收
							uni.setStorageSync('recevingAddressId',res.addressId);
							uni.navigateBack({
								delta:2
							})
						}
						
					}else{
						uni.showToast({
							title:"系统错误"+res.code,
							icon:'error'
						})
					}
				})
			},
			/* 图片识别 */
			photoDistinguish(){
				uni.showToast({
					title:'陆续开放中...',
					icon:'none'
				})
			}
		}
	}
</script>

<style>
	@font-face {
		font-family: 'wxfont';
		src: url('~@/static/webfont.ttf') format('truetype');
		/* chrome、firefox、opera、Safari, Android, iOS 4.2+*/

	}

	page {
		background-color: #F8F8F8;
	}

	input {
		height: 80upx;
	}

	.a1 {
		display: flex;
		flex-direction: row;
		align-items: center;
		padding-left: 30upx;
		margin-top: 30upx;
	}

	.content {
		background-color: #FFFFFF;
		padding-top: 30upx;
	}

	.a2 {
		width: 30upx;
		height: 30upx;
	}

	.a3 {
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
		width: 100%;
		padding-right: 20upx;
	}

	.a4 {
		padding-left: 30upx;
		letter-spacing: 1upx;
		width: 60%;
	}

	.a5 {
		color: #383838;
		font-size: 32upx;
		font-family: wxfont;
		padding-top: 20upx;
	}

	.a6 {
		color: #979797;
		font-size: 24upx;
		padding-top: 10upx;
	}

	.a7 {
		width: 25upx;
		height: 25upx;
	}

	.a8 {
		height: 1upx;
		background-color: #F1F1F1;
		width: 85%;
		margin: 30upx auto 0 85upx;
	}

	.a9 {
		padding-left: 30upx;
		font-size: 26upx;

		width: 80%;
	}

	.pc {
		color: #979797;
	}

	.b1 {
		box-shadow: 0 5upx 5upx 0 #C0C0C0;
		height: 270upx;
		width: 90%;
		margin: 30upx auto;
		background-color: #FFFFFF;
		border-radius: 15upx;
		padding-left: 30upx;
	}

	.b2 {
		font-size: 26upx;
		font-weight: 700;
		padding-top: 30upx;
	}

	.b3 {
		font-size: 26upx;
		padding-top: 20upx;
	}

	.b4 {
		display: flex;
		flex-direction: row;
		margin-top: 30upx;
		justify-content: space-between;
		padding-right: 30upx;
		align-items: center;
	}

	.b5 {
		display: flex;
		flex-direction: row;
	}

	.b6 {
		width: 30upx;
		height: 30upx;
		margin-right: 5upx;
	}

	.b7 {
		font-size: 22upx;
	}

	.b8 {
		font-size: 22upx;
		width: 100upx;
		height: 50upx;
		border-radius: 25upx;
		background-color: #979797;
		color: #FFFFFF;
		line-height: 50upx;
		text-align: center;
	}
	.confirm{
		background-color: #333333;
		color: #FFFFFF;
		text-align: center;
		height: 100upx;
		line-height: 100upx;
		border-radius: 50upx;
		position: fixed;
		bottom: 50upx;
		width: 80%;
		left:0;
		right:0;
		margin: auto;
	}
</style>
